package ru.spbau.bytecode.reader;

import static org.junit.Assert.assertEquals;

import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

import ru.spbau.bytecode.reader.BytecodeReader;

public class BytecodeReaderTest {
	
	private final BytecodeReader reader = new BytecodeReader();
	
	@Test
	public void testVertexReading() throws IOException {
		Set<String> classesInVertex = new HashSet<String>();
		classesInVertex.add("java.awt.Color");
		classesInVertex.add("java.lang.Object");
		classesInVertex.add("java.awt.Dimension");
		classesInVertex.add("java.awt.Font");
		classesInVertex.add("java.awt.Graphics");
		classesInVertex.add("java.awt.Point");
		classesInVertex.add("java.awt.font.FontRenderContext");
		classesInVertex.add("java.awt.geom.Rectangle2D");
		classesInVertex.add("java.awt.Rectangle");
		classesInVertex.add("java.lang.String");
		
		reader.run("resources/testData/Vertex.class");
		assertEquals(classesInVertex, reader.getClasses());
	}
	
	@Test
	public void testGetCurrentClass() throws IOException {
		reader.run("resources/testData/Vertex.class");
		assertEquals("ru.spbau.bytecode.graph.Vertex", reader.getCurrentClass());
	}
	
	@Test(expected = FileNotFoundException.class)
	public void testFileNotFoundException() throws IOException {
		reader.run("NoSuchFile.class");
	}
	
	@Test(expected = EOFException.class)
	public void testEOFException() throws IOException {
		reader.run("resources/testData/Tester.java");
	}
}
